import { DiamondNode, DiamondNodeModel, NodeConfig, GraphModel } from '@logicflow/core'
import { getBpmnId } from '../getBpmnId'
import './userTask.scss'
class UserTaskModel extends DiamondNodeModel {
  static extendKey = 'UserTaskModel'
  constructor(data: NodeConfig, graphModel: GraphModel) {
    if (!data.id) {
      data.id = `userTask_${getBpmnId()}`
    }
    if (!data.text) {
      data.text = ''
    }
    if (data.text && typeof data.text === 'string') {
      data.text = {
        value: data.text,
        x: data.x,
        y: data.y + 2,
      }
    }
    super(data, graphModel)
    this.rx = 80
    this.ry = 45
  }
  getNodeStyle() {
    const props = this.properties
    const style = super.getNodeStyle()
    style.stroke = '#b1cbe4'
    style.fill = '#b1cbe4'
    if (props.complete) {
      style.stroke = '#4097d7'
      style.fill = '#4097d7'
    }
    if (props.current) {
      style.stroke = '#29c7cd'
      style.fill = '#29c7cd'
    }
    return style
  }
  getTextStyle() {
    const style = super.getTextStyle()
    style.color = '#fff'
    style.fontSize = 16
    return style
  }
}

class UserTaskView extends DiamondNode {
  static extendKey = 'UserTaskNode'
}

const UserTask = {
  type: 'bpmn2:userTask',
  view: UserTaskView,
  model: UserTaskModel,
}

export { UserTaskView, UserTaskModel }
export default UserTask
